home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
CWL2A_1.ARJ
/
MENUDEMO.C
< prev
next >
Wrap
Text File
|
1991-11-16
|
18KB
|
538 lines
/* Date 11-1-91 */
/************************************************************************
* This is the demonstration program of the menu functions available *
* with The C Window Library. Uses a mouse if mouse is installed. *
* *
* For Turbo C version 1.5 and above, compile using the following: *
* tcc -mm -Ixxx menudemo.c tcwinm.lib tcmousem.lib *
* where xxx is the directory of The C Window Library header files. *
* *
* For Microsoft C users Version 5.1 and above: *
* cl -AM -DMSC -Ixxx menudemo /link /SE:1000 mswinm.lib msmousem.lib *
* (use "qcl" instead of "cl" if using Quick C) *
* where xxx is the directory of The C Window Library header files. *
* *
* For Zortech C++ Version 2.0 and above: *
* ztc -mm -p -b -Ixxx menudemo.c zcwinm.lib zcmousem.lib *
* where xxx is the directory of The C Window Library header files. *
* *
* For Power C Version 2.1 and above: *
* pc -DPOWERC -mm -c -ixxx menudemo.c *
* pcl [10k,30k,300k] menudemo;pcwinm;pcmousem *
* where xxx is the directory of The C Window Library header files. *
************************************************************************/
#include "menu.h"
#include "cwlmouse.h"
/* define colors */
#define YELLOWONRED CREATE_VIDEO_ATTRIBUTE(red,yellow)
#define WHITEONBLUE CREATE_VIDEO_ATTRIBUTE(blue,white)
#define BLUEONWHITE CREATE_VIDEO_ATTRIBUTE(white,blue)
#define BLACKONCYAN CREATE_VIDEO_ATTRIBUTE(cyan,black)
#define NORM CREATE_VIDEO_ATTRIBUTE(black,white)
#define BLACKONWHITE CREATE_VIDEO_ATTRIBUTE(white,black)
#define WHITEONRED CREATE_VIDEO_ATTRIBUTE(red,lightwhite)
#define INTROLINES 6
WPOINTER help,pw,intro,error_window;
VBLOCKPTR v;
int rt1(); /* Routine that is called when popup option is chosen */
int rt2(); /* Routine that is called when bar option is chosen */
int rt3(); /* Routine that is called when pulldown option is chosen */
int beep_it(); /* Routine that is called when undefined key is pressed */
void bar_demo(); /* Routine to do bar menu demo */
void popup_demo(); /* Routine to do popup demo */
void pulldown_demo(); /* Routine to do pulldown menu demo */
void custom_error_func();
void initialize_error();
int error_check_flag = 1; /* Turn error checking on (not to be
* confused with the internal variable
* check_window_error) */
char *intro_lines[] =
{"This is a demo of the menu functions",
"available with The C Window Library.",
"If you have a mouse, you can use the",
"mouse to make menu selections. ",
" ",
" Press a key to continue..."};
/*****************************
* Define popup menu entries *
****************************/
POPUP_MENU_ENTRY menu_items1[] = {
" Load F3", /* option name */
1, /* row number */
'L', /* hotkey */
F3, /* secondary hotkey */
rt1, /* function to call if chosen */
/* now do rest of the popup entries */
" Pick Alt-F3",2, 'P',ALTF3,rt1,
" New" ,3, 'N',0,rt1,
" Save F2",4, 'S',F2,rt1,
" Write to ",5, 'W',0,rt1,
" Directory ",6, 'D',0,rt1,
" Change Dir" ,7, 'C',0,rt1,
" OS shell" ,8, 'O',0,rt1,
" Quit Alt-X" ,9,'Q',ALTX,rt1,
/* Terminate with a NULL and 0 */
CWL_NULL,0};
POPUP_MENU_ENTRY menu_items3[] = {
" Run Ctrl-F9 ",1,'R',CTRLF9,rt3,
" Program reset Ctrl-F2 ",2,'P',CTRLF2,rt3,
" Go to Cursor F4 ",3,'G',F4,rt3,
" Trace into F7 ",4,'T',F7,rt3,
" Step over F8 ",5,'S',F8,rt3,
" User screen Alt-F5 ",6,'U',ALTF5,rt3,
CWL_NULL,0};
POPUP_MENU_ENTRY menu_items4[] = {
" Compile to OBJ ",1,'C',0,rt3,
" Make EXE file ",2,'M',0,rt3,
" Link EXE file ",3,'L',0,rt3,
" Build all ",4,'B',0,rt3,
" Primary C file: ",5,'P',0,rt3,
" Get info ",6,'G',0,rt3,
CWL_NULL,0};
POPUP_MENU_ENTRY menu_items5[] = {
" Project Name ",1,'P',0,rt3,
" Break make on ",2,'B',0,rt3,
" Auto dependencies ",3,'A',0,rt3,
" Clear project ",4,'C',0,rt3,
" Remove messages ",5,'R',0,rt3,
CWL_NULL,0};
POPUP_MENU_ENTRY menu_items6[] = {
" Compiler ",1,'C',0,rt3,
" Linker ",2,'L',0,rt3,
" Environment ",3,'E',0,rt3,
" Directories ",4,'D',0,rt3,
" Arguments ",5,'A',0,rt3,
" Save Options ",6,'S',0,rt3,
" Retrieve options ",7,'R',0,rt3,
CWL_NULL,0};
POPUP_MENU_ENTRY menu_items7[] = {
" Evaluate Ctrl-F4 ",1,'E',CTRLF4,rt3,
" Call Stack Ctrl-F3 ",2,'C',CTRLF3,rt3,
" Find Function ",3,'F',0,rt3,
" Refresh display ",4,'R',0,rt3,
" Display swapping Smart ",5,'D',0,rt3,
" Source debugging ",6,'S',0,rt3,
CWL_NULL,0};
POPUP_MENU_ENTRY menu_items8[] = {
" Add watch Ctrl-F7 ",1,'A',CTRLF7,rt3,
" Delete watch ",2,'D',0,rt3,
" Edit Watch ",3,'E',0,rt3,
" Remove all watches ",4,'R',0,rt3,
" Toggle breakpoint Ctrl-F8 ",6,'T',CTRLF8,rt3,
" Clear all breakpoints ",7,'C',0,rt3,
" View next breakpoint ",8,'V',0,rt3,
CWL_NULL,0};
/**********************
* Define Bar entries *
*********************/
BAR_MENU_ENTRY bar_items[] = {
"File", 1,4, 'F',0,rt2,
"Edit", 1,10,'E',0,rt2,
"Run", 1,17,'R',0,rt2,
"Compile", 1,23,'C',0,rt2,
"Project", 1,33,'P',0,rt2,
"Options", 1,43,'O',0,rt2,
"Debug", 1,53,'D',0,rt2,
"Break/watch",1,61,'B',0,rt2,
CWL_NULL};
/* Define array of POPUP_MENU_ENTRY's used for pulldown menu */
/* This array is used for convenience when initializing all of the
* POPUP_MENU_PTR's */
POPUP_MENU_ENTRY *pentry[] = {menu_items1, POPUP_ENTRY_NULL, menu_items3,
menu_items4, menu_items5, menu_items6,
menu_items7, menu_items8};
unsigned menu_colors[5]; /* Menu colors */
BAR_MENU_PTR bar; /* Pointer to bar menu */
POPUP_MENU_PTR popups[8]; /* Array of pointers to pop-up menus */
PULLDOWN_MENU_PTR pull; /* Pointer to pulldown menu */
WPOINTER my_open(); /* Pointer to custom bar window open function */
int popuprank[] = {1,1,1,1,1,1,1,1}; /* Ranks of pop-up windows */
unsigned popupstart[] = {1,1,1,1,1,1,1,1}; /* Starting option for each pop-up
menu */
int height[] = {9,0,6,6,5,7,6,8}; /* height of each window */
char *line =
"─────────────────────────────"; /* Horizontal line */
int which,hpos,vpos;
void main()
{
int i,d,b;
/* Get Choice of which screen method to use */
printf("\nPlease enter: '0' for Direct Screen Writes\n"
" '1' for Direct Screen Writes with snow checking\n"
" '2' for BIOS Screen updates: ");
scanf("%d",&d);
WindowInitializeSystem();
CHECK_SNOW = d;
SCREEN_WRITE_METHOD = (d == 2)?BIOS:DMA;
/* Save Initial Screen as a VBLOCK */
v = VideoSave(1,1,num_screen_rows,num_screen_cols);
ClearScreen(NORM);
/* Save Base Screen as a window */
WindowSaveInitial(active_video_page);
/* Initialize error function */
initialize_error();
intro = WindowInitialize(BORDER,1,1,36,INTROLINES,NORM,NORM,SINGLEBOX);
WindowOpen(intro);
/* Write introduction to window */
WindowCenter(intro,HORIZCENTER | VERTCENTER);
for (i=1;i<=INTROLINES;i++)
WindowWriteString(intro,intro_lines[i-1],i,1);
WindowDisplay(intro,1,EXPLODE);
GET_MPRESS_KEY(&which);
WindowFree(intro,CONTRACT);
/* Initialize mouse */
MouseInitializeSystem(MOUSE_FULL_INSTALL,&b,1,1);
/* Initialize Info Window */
pw = WindowInitialize(BORDER,19,10,50,4,CREATE_VIDEO_ATTRIBUTE(black,white),
CREATE_VIDEO_ATTRIBUTE(black,white), SINGLEBOX);
/* Open Info Window */
WindowOpen(pw);
/* Initialize And Open Help Window */
help = WindowInitialize(NOBORDER,25,1,80,1,BLACKONWHITE,BLACKONWHITE,0);
WindowOpen(help);
/* Write Help Info to help window */
WindowWriteCenterString(help,
"Press \030 or \031 or use mouse to move bar, ─┘ or hotkey to accept, ESC to exit",1);
/* define colors */
menu_colors[ENTRYCOLOR] =
menu_colors[UNAVAILCOLOR] =
menu_colors[BORDERCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
menu_colors[HOTKEYCOLOR] =
menu_colors[HIGHLIGHTCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,white);
/* Call Popup Demo */
popup_demo();
/* Call Bar Demo */
bar_demo();
/* Call Pulldown Demo */
pulldown_demo();
/* Restore Initial Screen */
VideoRestore(v);
/* Turn off mouse */
MouseRestoreSystem();
}
void popup_demo()
{
POPUP_MENU_PTR p;
/* create a POPUP_MENU_PTR */
p = PopupCreateMenu(menu_items1,menu_colors, 1,31,9,
POPUPSTATIC | POPUPMOUSE | POPUPWRAP | POPUPMOUSESCROLL,
WNULLFN,VWNULLFN);
/* Define routine to do when undefined key is pressed */
popup_undef_key = beep_it;
/* Display the help window */
WindowDisplay(help,1,NOEFFECT);
/* Call Selection Function */
PopupSelectMenu(p, /* POPUP_MENU_PTR */
1, /* rank of pop-up window */
1 /* menu option to start on */
);
/* Dispose of popup menu */
PopupMenuFree(p);
}
/* Routine that is called when popup function is invoked */
int rt1(POPUP_MENU_PTR p, int which)
{
WindowClear(pw);
/* Display the entry name that was chosen */
WindowPrintf(pw,"You have selected %s",POPUP_ENTRY_STRING(p,which));
WindowWriteCenterString(pw,"Press a key to continue",4);
/* Display the window with all the info */
WindowDisplay(pw,1,NOEFFECT);
GET_MPRESS_KEY(&which);
/* Hide the info window */
WindowHide(pw,NOEFFECT);
/* If "Quit Alt-X" was selected, then get out of popup menu */
if (which == 9)
return POPUP_EXIT;
/* Keep getting popup selections */
else
return POPUP_CONTINUE;
}
void bar_demo()
{
BAR_MENU_PTR b;
/* Create Bar Menu */
b = BarCreateMenu(bar_items, menu_colors,1,1,BARWRAP|BARSTATIC|BARMOUSE,
WNULLFN);
/* Assign routine to call when undefined key is pressed */
bar_undef_key = beep_it;
/* Clear and rewrite help info in help window */
WindowClear(help);
WindowWriteCenterString(help,
"Press \032 or \033 or use mouse to move bar ─┘ or hotkey to accept ESC to exit",1);
/* Call Bar Selection function */
BarSelectMenu(b, /* BAR_MENU_PTR */
1, /* Rank of bar window */
1); /* Starting Entry */
/* Dispose of Bar Menu */
BarMenuFree(b);
}
int rt2(BAR_MENU_PTR b, int which)
{
WindowClear(pw);
/* Display the entry name that was chosen */
WindowPrintf(pw,"You have selected %s",BAR_ENTRY_STRING(b,which));
WindowWriteCenterString(pw,"Press a key to continue",4);
WindowDisplay(pw,1,NOEFFECT);
GET_MPRESS_KEY(&which);
/* Hide window */
WindowHide(pw,NOEFFECT);
/* Keep getting selections */
return BAR_CONTINUE;
}
void pulldown_demo()
{
int i;
/* Rewrite help window */
WindowClear(help);
WindowWriteCenterString(help,
"Press \030 \031 \032 \033 or use mouse to move bar, ─┘ or hotkey to accept, ESC to exit",1);
/* Reassign functions of the bar menu entry */
for (i=0;i<=7;i++)
bar_items[i].func = NULLFN;
/* Make special case for "Edit" entry */
bar_items[1].func = rt3;
/* Reassign function for the menu_items1 POPUP_MENU_ENTRY */
for (i=0;i<=8;i++)
menu_items1[i].func = rt3;
/* Create a BAR_MENU_PTR */
bar = BarCreateMenu(bar_items, /* Array of BAR_MENU_ENTRY's */
menu_colors,/* Pointer to menu colors */
6, /* Row to open bar menu window */
1, /* Column to open bar menu window */
BARWRAP | BARSTATIC | BARMOUSE,
my_open); /* Customized window open function */
/* Now loop to create all pop-up menus
Be careful and asign NULL to the second pop-up menu */
for (i=0; i<8; i++) /* Loop for all pop-up menus */
{
if (pentry[i] != POPUP_ENTRY_NULL) /* Skip over NULL pop-up window */
{
popups[i] =
PopupCreateMenu(pentry[i], /* Array of POPUP_MENU_ENTRY's */
menu_colors, /* Array of menu colors, */
/* The next two arguments will later be ignored */
1, /* Row to open pop-up window on */
1, /* Column to open pop-up */
height[i], /* height of the pop-up window */
/* No custom window open
functions */
POPUPWRAP | POPUPSTATIC | POPUPMOUSE,
WNULLFN,
VWNULLFN);
}
else
popups[i] = POPUP_NULL_PTR; /* Assign NULL to second pop-up window */
} /* end for (i=0 ... */
VirtualWriteString(POPUP_VIRTUAL_WINDOW(popups[7]),line,5,1);/* Draw horizontal line in virtual
popup window popups[7] */
PopupMakeEntryUnavailable(popups[6],2); /* hide 2nd and 3rd entries in */
PopupMakeEntryUnavailable(popups[6],3); /* popups[6] */
/* Now put bar and array of POPUP_MENU_PTR's together by calling
PulldownCreateMenu() */
pull = PulldownCreateMenu(popups,bar,1);
/* Call Pulldown Select function */
PulldownSelectMenu(pull,1,1,popuprank,popupstart,1);
/* Dispose of pulldown menu and all other menus used to build it */
PulldownMenuFreeAll(pull);
}
int rt3(PULLDOWN_MENU_PTR p, BAR_MENU_PTR b, POPUP_MENU_PTR pop,
int hs, int vs)
{
int ch;
WindowClear(pw);
WindowPrintf(pw,"You have selected bar option %s\n",
BAR_ENTRY_STRING(b,hs));
if (pop != (POPUP_MENU_PTR)0)
WindowPrintf(pw,"Popup entry %s",POPUP_ENTRY_STRING(pop,vs));
WindowWriteCenterString(pw,"Press a key to continue...",3);
WindowDisplay(pw,1,NOEFFECT);
ch = GET_MPRESS_KEY(&which);
WindowHide(pw,NOEFFECT);
if (ch == ESC)
return PULLDOWN_CONTINUE;
return PULLDOWN_CONTINUE;
}
WPOINTER my_open() /* Custom window open function for bar menu */
{
WPOINTER w;
w = WindowInitialize(NOBORDER,1,1,80,1,BLACKONWHITE,BLACKONWHITE,"");
WindowOpen(w);
return w;
}
int beep_it()
{
MakeSound(100,200); /* Produce error tone */
return DONT_PROCESS;
}
void initialize_error() /* Initialize error window and error handler */
{
error_window =
WindowInitialize(BORDER,1,1,60,5,WHITEONRED,WHITEONRED,SINGLEBOX);
WindowOpen(error_window);
window_error_func = custom_error_func; /* Assign error function */
}
void custom_error_func(int errcode, char *sourcefile, int sourceline,
char *funcname)
{
int ch;
if (error_check_flag)
{
MakeSound(100,500); /* Beep */
if (errcode == NO_HEAP_MEM) /* Always check for the heap memory error
separately */
{
VideoWriteString("You have ran out of Heap Memory",1,1);
VideoWriteString(
"Press 'Q' to quit program, Any other key to Continue...",2,1);
}
else /* Display error window */
{
WindowClear(error_window);
WindowDisplay(error_window,1,EXPLODE);
WindowPrintf(error_window,
"Error Code: %d\nSource File: %s\nSource Line %d\nError Occurred in %s",
errcode,sourcefile,sourceline,funcname);
WindowWriteString(error_window,
"Press 'Q' to quit program, Any other key to Continue...",5,1);
}
ch = GET_MPRESS_KEY(&which);
if (ch == 'Q' || ch == 'q')
{
VideoRestore(v);
exit(0);
}
else
if (errcode != NO_HEAP_MEM)
WindowHide(error_window,CONTRACT);
}
}